import Vector2 from "./Vector2.js"

export default class Area{
  width:number = 0
  height:number = 0
  position:Vector2
  constructor(x:number=0,y:number=0,width:number=0,height:number = 0){
    this.width = width
    this.height = height
    this.position = new Vector2(x,y)
    this._x = x
    this._y = y;
  }

  private _x:number = 0
  public set x(val:number){
    this._x = val;
    this.position.x = val
  }
  public get x(){
    return this._x;
  }

  
  private _y : number = 0;
  public get y() : number {
    return this._y;
  }
  public set y(v : number) {
    this._y = v;
    this.position.y = v
  }

  public isOverLap(other:Area):boolean{
    if (
      Math.abs(this.x + this.width / 2 - (other.x + other.width / 2)) <
        Math.abs(this.width + other.width) / 2  &&
      Math.abs(this.y + this.height / 2 - (other.y + other.height / 2)) <
        Math.abs(this.height + other.height) / 2 
    ) {
      return true
    }
    return false
  }
  
}